home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / c / ExtrasLib.lha / ExtrasLib / Source / GetNNData.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  1.6 KB  |  85 lines

  1. #include <stdlib.h>
  2. #include <string.h>
  3.  
  4. #include <clib/extras/db_protos.h>
  5. #include <clib/extras/nnstring_protos.h>
  6. #include <clib/extras_protos.h>
  7. #include <extras/macros.h>
  8. #include "entries.h"
  9.  
  10. #include <exec/types.h>
  11.  
  12. /****** extras.lib/nns_GetNNData ******************************************
  13. *
  14. *   NAME
  15. *       nns_GetNNData -- Find data in a NNString
  16. *
  17. *   SYNOPSIS
  18. *       STRPTR GetNNData(STRPTR NNStr, STRPTR Name, STRPTR DefVal);
  19. *
  20. *   FUNCTION
  21. *       Retrieves data from a NNString.
  22. *
  23. *       nnstr="TITLE=Joe\0COLOR=Green\0TITLE=Test\0\0"
  24. *
  25. *       t=GetNNData(nnstr,"TITLE","None");
  26. *
  27. *       t will equal "Joe\0Test\0\0"
  28. *
  29. *   SEE ALSO
  30. *
  31. ******************************************************************************
  32. *
  33. */
  34.  
  35.  
  36. STRPTR nns_GetNNData(STRPTR NNStr, STRPTR Name, STRPTR DefVal)
  37. {
  38.   STRPTR s,rv=0;
  39.   LONG namelen;
  40.  
  41.   if(!GED_Buffer)
  42.   {
  43.     GED_Buffer=malloc(BUFFERSIZE);
  44.     if(!GED_Buffer)
  45.       return(0);
  46.   }
  47.   
  48.   GED_Buffer[0]=0;
  49.  
  50.   if(NNStr && Name)
  51.   {
  52.     namelen=strlen(Name);
  53.     nns_ProcessNNStr(NNStr,s)
  54.     {
  55.       if(strnicmp(s,Name,namelen)==0)
  56.       {
  57.         STRPTR value;
  58.           
  59.         value=s+namelen;
  60.         
  61.         while(IsWhiteSpace(*value))
  62.         {
  63.           value++;
  64.         }
  65.         
  66.         if(*value=='=')
  67.         {
  68.           value++;
  69.           strncpy(GED_Buffer,value,BUFFERSIZE);
  70.           GED_Buffer[BUFFERSIZE]=0;
  71.           value=GED_Buffer;
  72.           Strip(value);
  73.           if(!(rv=nns_AddNNStr(rv,value)))
  74.           {
  75.             return(0);
  76.           }
  77.         }
  78.       }
  79.     }
  80.     if(!rv)
  81.       rv=nns_AddNNStr(0,DefVal);
  82.   }
  83.   return(rv);
  84. }
  85.